package com.bajiao.service.discountRule.impl;

import com.bajiao.entity.discountRule.UserDiscountMark;
import com.bajiao.mapper.discountRule.UserDiscountMarkMapper;
import com.bajiao.service.discountRule.UserDiscountMarkService;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

/**
 * @Description: 用户优惠标示
 * @Author: FanJq
 * @Date:   2025-01-13
 * @Version: V1.0
 */
@Service
public class UserDiscountMarkServiceImpl extends ServiceImpl<UserDiscountMarkMapper, UserDiscountMark> implements UserDiscountMarkService {

    /**
     * @Description
     * 获取店铺优惠标示
     * @date 2025/1/13 14:43
     * @author FanJq
     * @param userId
     * @param storeId
     * @return {@link UserDiscountMark}
    */
    @Override
    public UserDiscountMark getUserStoreMark(String userId, String storeId) {
        UserDiscountMark discountMark = super.lambdaQuery()
                .eq(UserDiscountMark::getUserId, userId)
                .eq(UserDiscountMark::getStoreId, storeId)
                .one();
        return discountMark;
    }

    /**
     * @Description
     * 更新标识
     * @date 2025/1/13 19:18
     * @author FanJq
     * @param userId
     * @param storeId
     * @param mark
     * @return
    */
    @Override
    public void modify(String userId, String storeId, Integer mark) {
        super.lambdaUpdate()
                .set(UserDiscountMark::getMark, mark)
                .set(UserDiscountMark::getNextMark, mark + 1)
                .eq(UserDiscountMark::getUserId, userId)
                .eq(UserDiscountMark::getStoreId, storeId)
                .update();
    }
}
